﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using System.Data;

namespace Catering.UserTraining.SlrCompanyTrainning
{
    public partial class cpntraining_test_que_list : UserIsNull
    {
        public string m_UserID = "0";
        public int m_TestID = 0;
        public int m_LessonID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] != null) m_UserID = Session["UserID"].ToString();
            m_TestID = CommRequest.GetInt("TestID", 0);
            m_LessonID = CommRequest.GetInt("LessonID", 0);
            if (!IsPostBack)
            {
                this.LoadRep();
            }
        }

        //绑定Rep控件
        public void LoadRep()
        {
            this.lbl_TextName.Text = new Catering_Rules.Tests().GetModel(m_TestID).TestName;
            DataTable dt_PurchaseInfo = new Catering_Rules.TestsQueList().GetList(" 1=1 AND TestID=" + m_TestID + " ").Tables[0];//分页处理
            this.Repeater1.DataSource = dt_PurchaseInfo;
            this.Repeater1.DataBind();
        }

        /// <summary>
        /// 新增功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_test_que_add.aspx?LessonID=" + m_LessonID + "&TestID=" + m_TestID;
            Response.Redirect(url);
        }

        protected void btn_ReturnIndex_Click(object sender, EventArgs e)
        {
            string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_test_list.aspx?LessonID=" + m_LessonID;
            Response.Redirect(url);
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int QueID = int.Parse(e.CommandArgument.ToString());
            if (QueID <= 0) return;
            if (e.CommandName == "del")
            {
                if (new Catering_Rules.TestsQueList().Delete(QueID))
                {
                    this.LoadRep();
                    ScriptManager.RegisterStartupScript(this, GetType(), "Affect", "alert('删除成功！')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "Affect", "alert('删除失败！')", true);
                }
            }
            else if (e.CommandName == "edit")
            {
                string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_test_que_add.aspx?Flag=EDIT&LessonID=" + m_LessonID + "&TestID=" + m_TestID + "&QueID=" + QueID;
                Response.Redirect(url);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.LoadRep();
        }
    }
}